<?php
require_once ROOT_PATH . '/lib/common/SearchObject.php';
require_once ROOT_PATH.'/lib/models/pa/paResults.php';

/** PHPExcel */
require_once ROOT_PATH . '/lib/Classes/PHPExcel.php';
require_once ROOT_PATH . '/lib/Classes/PHPExcel/Worksheet/PageSetup.php';
require_once ROOT_PATH .'/lib/Classes/PHPExcel/IOFactory.php';

 class EXTRACTOR_PA_Results {

 	public function parseImportPAResults(){
 		$paResults = array();
 		if ( isset( $_FILES['fImportFile'] ) && in_array($_FILES['fImportFile']['type'],array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))) {
 			$inputFileType = 'Excel2007';
			$objReader = PHPExcel_IOFactory::createReader($inputFileType);
			$objPHPExcel = $objReader->load($_FILES["fImportFile"]["tmp_name"]);
			$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
			for($i=3;$i<(count($sheetData)+1);$i++){
				$excelArr = $sheetData[$i];
				if(strlen($excelArr['A'])==5){
				$paResult = PAResults::getPAResultByEmpCode($excelArr['A']);
				$paResult->setEmployeeCode($excelArr['A']);
		    	$paResult->setPAType($_POST['jobTitle']);
		    	$paResult->setCurrentLevel($excelArr['D']);
		    	$paResult->setNewLevel($excelArr['E']);
		    	$paResult->setExpectLevel($excelArr['F']);
		    	$paResult->setCurrentNetSalary($excelArr['G']);
		    	$paResult->setCurrentGrossSalary($excelArr['H']);
		    	$paResult->setCurrentContractSalary($excelArr['I']);
		    	$paResult->setNewNetSalary($excelArr['J']);
		    	$paResult->setPAAdjust($excelArr['K']);
		    	$paResult->setPALevelAdjust($excelArr['L']);
		    	$paResult->setNewGrossSalary($excelArr['M']);
		    	$paResult->setNewContractSalary($excelArr['N']);

		    	$paResult->setPerformanceOnJob($excelArr['O']);
		    	$paResult->setJobKnowledge($excelArr['P']);
		    	$paResult->setTeamWork($excelArr['Q']);
		    	$paResult->setManagement($excelArr['R']);
		    	$paResult->setDisciplined($excelArr['S']);
		    	$paResult->setCommunication($excelArr['T']);
		    	$paResult->setCorporateDevelopment($excelArr['U']);
		    	$paResult->setPAEnglish($excelArr['V']);
		    	$paResult->setPracticalEnglish($excelArr['W']);
		    	$paResult->setTestEnglish($excelArr['X']);
		    	$paResult->setPAScore($excelArr['Y']);
		    	$paResults[]=$paResult;
				}
			}
	 	}
	 	return $paResults;
 	}


	public function parseAddSkillGroup($postArr){
		$skillGroup = new SkillGroup();
		$skillGroup->setSkillGroupName($postArr['skill_group_name']);

 		if (isset($postArr['skill_group_type']) && !empty($postArr['skill_group_type'])) {
			$skillGroup->setSkillGroupType(implode(",",$postArr['skill_group_type']));
		}
		return $skillGroup;
	}
 	public function parseUpdateSkillGroup($postArr){
		$id=$postArr['skill_group_id'];
 		$skillGroup = SkillGroup::getSkillGroup($id);

		$skillGroup->setSkillGroupName($postArr['skill_group_name']);

 		if (isset($postArr['skill_group_type'])) {
			$skillGroup->setSkillGroupType(implode(",",$postArr['skill_group_type']));
		}
		return $skillGroup;
	}

 	public function parseAddSkillExpertise($postArr){
		$skillExpertise = new SkillExpertise();
		$skillExpertise->setSkillExpertiseName($postArr['skill_expertise_name']);
		$skillExpertise->setSkillGroupID($postArr['skill_expertise_group_id']);
		$skillExpertise->setSkillExpertiseOrder(0);
		return $skillExpertise;
	}


}
?>